package com.example.Arithmetic.Arithmetic;

import java.util.Arrays;

/**
 * 日期：2023/12/26
 * 时间：22:18
 * 描述：冒泡排序
 */
public class BubbleSort {
    public void bubble(int[] ints) {
        int j = ints.length - 1;
        while (true) {
            int x = 0;
            for (int i = 0; i < j; i++) {
                if (ints[i] > ints[i + 1]) {
                    int t = ints[i];
                    ints[i] = ints[i + 1];
                    ints[i + 1] = t;
                    x = i;
                }
            }
            j = x;
            if (j == 0) {
                break;
            }
        }
    }
    public static void main(String[] args) {
        int[] a = {2, 3, 1, 7, 6, 4, 5};
        System.out.println(Arrays.toString(a));
        BubbleSort bubbleSort=new BubbleSort();
        bubbleSort.bubble(a);
        System.out.println(Arrays.toString(a));
    }
}
